package com.guys8.cemsbackend.DTO;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * 响应主体
 *
 * @author Breeze
 * @param <T>
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response<T> implements Serializable {

    private int responseCode;
    private List<T> data;

    public static <T> Response<T> restResult(int code, T... Tdata) {
        Response<T> apiResult = new Response<>();
        apiResult.setResponseCode(code);
        apiResult.setData(new LinkedList<>());
        for(T data:Tdata) {
            apiResult.getData().add(data);
        }
        return apiResult;
    }
    public static <T> Response<T> restResult(int code) {
        Response<T> apiResult = new Response<>();
        apiResult.setResponseCode(code);
        apiResult.setData(null);
        return apiResult;
    }
}
